From b52ad33031c06ad517a704bc055f93c9920e4b4f Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Tue, 28 Jul 2020 16:51:41 +0200 Subject: [PATCH] gdk: Add gdk_seat_get_tools() API call There's GdkSeat::tool-added and ::tool-removed, but there's no API to query the known tools. Add this call. --- docs/reference/gdk/gdk4-sections.txt | 1 + gdk/gdkseat.c | 37 +++++++++++++++++++++++++++- gdk/gdkseat.h | 2 ++ gdk/gdkseatdefault.c | 16 +++++------- gdk/gdkseatprivate.h | 4 +-- gdk/wayland/gdkdevice-wayland.c | 17 +++++++++++++ 6 files changed, 63 insertions(+), 14 deletions(-) diff --git a/docs/reference/gdk/gdk4-sections.txt b/docs/reference/gdk/gdk4-sections.txt index 7e142c3310..a863bae857 100644 --- a/docs/reference/gdk/gdk4-sections.txt +++ b/docs/reference/gdk/gdk4-sections.txt @@ -439,6 +439,7 @@ gdk_seat_get_capabilities gdk_seat_get_pointer gdk_seat_get_keyboard gdk_seat_get_physical_devices +gdk_seat_get_tools GDK_SEAT diff --git a/gdk/gdkseat.c b/gdk/gdkseat.c index 6505169c33..8b6a88997c 100644 --- a/gdk/gdkseat.c +++ b/gdk/gdkseat.c @@ -22,6 +22,7 @@ #include #include "gdkdisplay.h" #include "gdkdevice.h" +#include "gdkdevicetoolprivate.h" #include "gdkseatprivate.h" #include "gdkdeviceprivate.h" #include "gdkintl.h" @@ -438,11 +439,45 @@ GdkDeviceTool * gdk_seat_get_tool (GdkSeat *seat, guint64 serial, guint64 hw_id) +{ + GdkDeviceTool *match = NULL; + GList *tools, *l; + + tools = gdk_seat_get_tools (seat); + + for (l = tools; l; l = l->next) + { + GdkDeviceTool *tool = l->data; + + if (tool->serial == serial && tool->hw_id == hw_id) + { + match = tool; + break; + } + } + + g_list_free (tools); + + return match; +} + +/** + * gdk_seat_get_tools: + * @seat: A #GdkSeat + * + * Returns all #GdkDeviceTools that are known to the + * application. + * + * Returns: (transfer container) (element-type Gdk.DeviceTool): A list of tools. Free with + * g_list_free(). + **/ +GList * +gdk_seat_get_tools (GdkSeat *seat) { GdkSeatClass *seat_class; g_return_val_if_fail (GDK_IS_SEAT (seat), NULL); seat_class = GDK_SEAT_GET_CLASS (seat); - return seat_class->get_tool (seat, serial, hw_id); + return seat_class->get_tools (seat); } diff --git a/gdk/gdkseat.h b/gdk/gdkseat.h index 960a6e306b..1802d5348f 100644 --- a/gdk/gdkseat.h +++ b/gdk/gdkseat.h @@ -78,6 +78,8 @@ GDK_AVAILABLE_IN_ALL GList * gdk_seat_get_physical_devices (GdkSeat *seat, GdkSeatCapabilities capabilities); +GList * gdk_seat_get_tools (GdkSeat *seat); + GDK_AVAILABLE_IN_ALL GdkDevice * gdk_seat_get_pointer (GdkSeat *seat); GDK_AVAILABLE_IN_ALL diff --git a/gdk/gdkseatdefault.c b/gdk/gdkseatdefault.c index bf7537ef5a..dd44233a6b 100644 --- a/gdk/gdkseatdefault.c +++ b/gdk/gdkseatdefault.c @@ -279,13 +279,12 @@ gdk_seat_default_get_physical_devices (GdkSeat *seat, return devices; } -static GdkDeviceTool * -gdk_seat_default_get_tool (GdkSeat *seat, - guint64 serial, - guint64 hw_id) +static GList * +gdk_seat_default_get_tools (GdkSeat *seat) { GdkSeatDefaultPrivate *priv; GdkDeviceTool *tool; + GList *tools = NULL; guint i; priv = gdk_seat_default_get_instance_private (GDK_SEAT_DEFAULT (seat)); @@ -296,12 +295,10 @@ gdk_seat_default_get_tool (GdkSeat *seat, for (i = 0; i < priv->tools->len; i++) { tool = g_ptr_array_index (priv->tools, i); - - if (tool->serial == serial && tool->hw_id == hw_id) - return tool; + tools = g_list_prepend (tools, tool); } - return NULL; + return tools; } static void @@ -319,8 +316,7 @@ gdk_seat_default_class_init (GdkSeatDefaultClass *klass) seat_class->get_logical_device = gdk_seat_default_get_logical_device; seat_class->get_physical_devices = gdk_seat_default_get_physical_devices; - - seat_class->get_tool = gdk_seat_default_get_tool; + seat_class->get_tools = gdk_seat_default_get_tools; } static void diff --git a/gdk/gdkseatprivate.h b/gdk/gdkseatprivate.h index 07672f6a44..90e8a8674c 100644 --- a/gdk/gdkseatprivate.h +++ b/gdk/gdkseatprivate.h @@ -57,9 +57,7 @@ struct _GdkSeatClass GList * (* get_physical_devices) (GdkSeat *seat, GdkSeatCapabilities capabilities); - GdkDeviceTool * (* get_tool) (GdkSeat *seat, - guint64 serial, - guint64 tool_id); + GList * (* get_tools) (GdkSeat *seat); }; void gdk_seat_device_added (GdkSeat *seat, diff --git a/gdk/wayland/gdkdevice-wayland.c b/gdk/wayland/gdkdevice-wayland.c index 8096782ad0..d9a9a95672 100644 --- a/gdk/wayland/gdkdevice-wayland.c +++ b/gdk/wayland/gdkdevice-wayland.c @@ -4749,6 +4749,22 @@ gdk_wayland_seat_get_physical_devices (GdkSeat *seat, return physical_devices; } +static GList * +gdk_wayland_seat_get_tools (GdkSeat *seat) +{ + GdkWaylandSeat *wayland_seat = GDK_WAYLAND_SEAT (seat); + GList *tools = NULL, *l; + + for (l = wayland_seat->tablet_tools; l; l = l->next) + { + GdkWaylandTabletToolData *tool = l->data; + + tools = g_list_prepend (tools, tool->tool); + } + + return tools; +} + static void gdk_wayland_seat_class_init (GdkWaylandSeatClass *klass) { @@ -4762,6 +4778,7 @@ gdk_wayland_seat_class_init (GdkWaylandSeatClass *klass) seat_class->ungrab = gdk_wayland_seat_ungrab; seat_class->get_logical_device = gdk_wayland_seat_get_logical_device; seat_class->get_physical_devices = gdk_wayland_seat_get_physical_devices; + seat_class->get_tools = gdk_wayland_seat_get_tools; } static void -- 2.30.2